﻿#define DEBUG_AGENT
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Scheduler;

namespace QuickTasks.ViewModels
{
    public class agent
    {
        public void startPeriodicTask()
        {
            PeriodicTask task = new PeriodicTask("Quick Task");

            task.Description = "Periodically Updates Contact Details for Quick Task and Sets Reminders based on Location";

            task.ExpirationTime = DateTime.Now.AddDays(12);
            var oldTask = ScheduledActionService.Find("Quick Task") as PeriodicTask;
            if (oldTask != null)
                ScheduledActionService.Remove("Quick Task");
            try
            {
                ScheduledActionService.Add(task);
//#if(DEBUG_AGENT)
//                ScheduledActionService.LaunchForTest("Quick Task", TimeSpan.FromSeconds(6));
//#endif
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Can't schedule agent; either there are too many other agents scheduled or you have disabled this agent in Settings.");
                return;
            }
        }
        public void startResourceIntensiveTask()
        {
            ResourceIntensiveTask task = new ResourceIntensiveTask("QuickTask");
            task.Description = "Sets Reminders based on Location";
            task.ExpirationTime = DateTime.Now.AddDays(12);
            var oldTask = ScheduledActionService.Find("QuickTask") as ResourceIntensiveTask;
            if (oldTask != null)
                ScheduledActionService.Remove("QuickTask");
            try
            {
                ScheduledActionService.Add(task);
#if(DEBUG_AGENT)
                ScheduledActionService.LaunchForTest("QuickTask", TimeSpan.FromSeconds(6));
#endif
            }
            catch (InvalidOperationException)
            {
                MessageBox.Show("Can't schedule agent; either there are too many other agents scheduled or you have disabled this agent in settings.");
                return;
            }

        }
    }
}
